package com.saisai.spring.component;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * <Description> <br>
 *
 * @author yss<br>
 * @version 1.0<br>
 * @createDate 2020/12/18 20:04 <br>
 */
public class CicleCase {

	public static void main(String[] args) {
		ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
		A a = ctx.getBean(A.class);
		a.hardWord();
	}
}

@Component
class A {
	// A中注入了B
	@Autowired
	private B b;

	public void hardWord() {
		System.out.println("A is hard working !");
	}
}

@Component
class B {
	// B中也注入了A
	@Autowired
	private A a;
}

@Configuration
@ComponentScan(basePackages = "com.saisai")
class AppConfig  {

}

